<?php

function calcDistance ($point, $blocked=array()) {
	$gmap = new gmap();

	foreach ($point as $index => $settings) {
		$point[$index]["from"] = $index;

		foreach ($point as $nextIndex => $nextSettings) {
			if ($index != $nextIndex) {
				$blockIt = FALSE;

				foreach ($blocked as $blockIndex => $blockValue) {
					if ($blockValue == $index || $blockValue == $settings["search"]) {
						$blockIt = TRUE;
						break;
					}
				}

				if ($blockIt === TRUE) {
					break;
				}
				else {
					#-> Ask Google for Distance
					for ($iDis=0; $iDis <= $config["gmap"]["attempts"]; $iDis++) {
						$disToNext = $gmap->getDis($settings["latitude"].", ".$settings["longitude"], $nextSettings["latitude"].", ".$nextSettings["longitude"]);

						if ($disToNext > 0) {
							$point[$index]["distance"][$nextIndex] = $disToNext;
							break;
						}
					}
				}
			}
		}
	}

	return $point;
}

?>